/*StaffInfo  */
import request from "/@/utils/request";
import download from "/@/utils/download.ts";

const StaffInfoApi = {

    getPageData(data: any) {
        return request({
            url: "/staffInfo/pageData",
            method: "post",
            data,
        });
    },
    getDetail(data: any) {
        return request({
            url: "/staffInfo/getDetail",
            method: "post",
            data,
        });
    },

    save: (data: any) => {
        return request({
            url: "/staffInfo/save",
            method: "post",
            data,
        });
    },

    del: (data: any) => {
        return request({
            url: "/staffInfo/del",
            method: "post",
            data,
        });
    },

//      downloadAttachment:(url: any) => {
//       console.log("url",url)
//       const item = url.split("/")
//       const fileName = item[item.length - 1]
//       console.log("fileName：",fileName)
//       axios({
//           method: "get",
//           url,
//           responseType:"blob"
//       }
//       ).then(res=>{
//           download(res,fileName)
//       })
//   },

      downloadAttachment(url: string) {
        // 创建一个 a 标签，模拟点击下载
        const link = document.createElement('a');
        link.href = url;
        link.target = '_blank'; // 在新标签页中打开，避免当前页面跳转
        link.download = url.substring(url.lastIndexOf('/') + 1); // 设置下载的文件名

        document.body.appendChild(link);
        link.click();
        document.body.removeChild(link); // 移除 a 标签
    },

    updateStatus: (data: any) => {
        return request({
            url: "/staffInfo/updateStatus",
            method: "post",
            data,
        });
    },
    
      pageDataXls:(_searchParam: any,_xlsTitle: any,_xlsName: any) => {
        const param = new URLSearchParams();
        param.append("_searchParam",JSON.stringify(_searchParam))
        param.append("_xlsTitle",_xlsTitle)
        param.append("_xlsName",_xlsName)
        return request({
            url: "/staffInfo/pageDataXls", 
            method: "post",
            responseType: 'blob',
            params:param,
        }).then((res)=> {
            download(res)
        });
    },
    uploadExcel: (data: any)=>{
        return request({
            url: "/staffInfo/importDataXls",
            method: "post",
            headersType:'multipart/form-data',
            data,
        })
    }, 

    batchSave: (data:any)=>{
        return request({
            url: "/staffInfo/batchSave",
            headersType: 'application/json;charset=UTF-8',
            method: "post",
            data,
        })
    },
    
};
export default StaffInfoApi;
